/**
 * 2013-01-23 05:05:05 -> 20130123050505
 * 
 * @param {}
 *            obj
 * @param {}
 *            defaultTime
 * @return {}
 */
function parseTime(obj, defaultTime) {
	var s = "";
	if (obj.indexOf("-") > -1) {
		f = obj.substring(0, obj.indexOf("-"));
		m = obj.substring(obj.indexOf("-") + 1, obj.lastIndexOf("-"));
		e = obj.substring(obj.lastIndexOf("-") + 1, obj.lastIndexOf("-") + 3);
		s = f + m + e;
	}

	if (obj.indexOf(":") > -1) {
		hh = obj.substring(obj.indexOf(":") - 2, obj.indexOf(":"));
		mm = obj.substring(obj.indexOf(":") + 1);
		ss = "00";
		s += hh + mm + ss;

	} else if (defaultTime != null) {
		s += defaultTime;
	}

	return s;
};

/**
 * 2013-01-23 -> 20130123
 * 
 * @param {}
 *            obj
 * @param {}
 *            defaultTime
 * @return {}
 */
function parseDate(obj, defaultTime) {
	var s = "";
	if (obj.indexOf("-") > -1) {
		f = obj.substring(0, obj.indexOf("-"));
		m = obj.substring(obj.indexOf("-") + 1, obj.lastIndexOf("-"));
		e = obj.substring(obj.lastIndexOf("-") + 1);
		s = f + m + e;

		if (defaultTime != null) {
			s += defaultTime
		}
	}

	return s;
};

/**
 * 20130123050505 -> 2013-01-23 05:05:05
 * 
 * @param {}
 *            obj
 * @param {}
 *            defaultTime
 * @return {}
 */
function formatTime(obj, defaultTime) {
	var s = "";
	if (obj.length == 8) {
		f = obj.substring(0, 4);
		m = obj.substring(4, 6);
		e = obj.substring(6, 8);
		s = f + "-" + m + "-" + e;
	} else if (obj.length == 14) {
		f = obj.substring(0, 4);
		m = obj.substring(4, 6);
		e = obj.substring(6, 8);
		h = obj.substring(8, 10);
		mm = obj.substring(10, 12);
		ss = obj.substring(12, 14);
		s = f + "-" + m + "-" + e + " " + h + ":" + mm + ":" + ss;
	}

	return s;
};

/**
 * 20130123 -> 2013-01-23
 * 
 * @param {}
 *            obj
 * @param {}
 *            defaultTime
 * @return {}
 */
function formatDate(obj, defaultTime) {
	var s = "";
	if (obj.length >= 8) {
		f = obj.substring(0, 4);
		m = obj.substring(4, 6);
		e = obj.substring(6, 8);
		s = f + "-" + m + "-" + e;
	}

	return s;
}

/**
 * json object to string
 * @param {} jsonObj
 * @return {}
 */
function json2param(jsonObj) {
	var str = "";

	if (jsonObj == null) {
		// alert();
		// do nothing
	} else if (jsonObj instanceof Array) {
		// alert();
		// do nothing
	} else if (jsonObj instanceof Object) {
		for (var property in jsonObj) {
			var val = jsonObj[property];
			if (typeof(val) != "function") {
				str += property + "=" + val + "&";
			}
		}
	}

	return (str.length != "" ? str.substring(0, str.length - 1) : str);
}

/**
 * string to json object
 * @param {} param
 * @return {}
 */
function param2json(param) {
	return (typeof(param) == "string"
			? (new Function("return " + param))()
			: param)
}